﻿@model VietPublisher.BaseProject.Models.cart.Cart
<script type="text/javascript" charset="utf-8">
//    var oTable;
//    $(document).ready(function () {
//        $('#example').dataTable({
//            "sScrollY": "200px",
//            "bPaginate": true
//            // "bSort": false
//            //"bFilter": false //search textbox is disable

//        });



//        /* Add a click handler to the rows - this could be used as a callback */
//        $("#example tbody tr").click(function (e) {
//            //alert(oTable);
//            if ($(this).hasClass('row_selected')) {
//                $(this).removeClass('row_selected');
//            }
//            else {
//                oTable.$('tr.row_selected').removeClass('row_selected');

//                $(this).addClass('row_selected');
//            }
//        });


//        /* Init the table */
//        oTable = $('#example').dataTable();
//    });

    function isNumberKey(evt,bookID) {
        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            return false;
        }
        return true;
    }

    function fnUpdateQuantity(bookId) {
        var quantity = $("#"+bookId).val();     
        $("#dvListCart").load("/Home/UpdateQuantity?bookId=" + bookId + "&quantity=" + quantity);
       
    }

    function fnRemoveCartItem(bookId) {
        $("#dvListCart").load("/Home/RemoveCartItem?bookId=" + bookId, function () {
            reloadLogon();
        });
    }//close function

    function fnEmptyCart() {
        $("#dvListCart").load("/Home/EmptyCart", function () {            
            reloadLogon();
        });
    }

</script>           
@if (Model.items.Count != 0)
{

<table id="example" class="display" width="100%">
    <thead>
        <tr class="">
            <th style="width:250px;">
                Name
            </th>
            <th>
                Book Code
            </th>
            <th>
                Price 
            </th>
            <th>
                Quantity
            </th>
            <th>
                Total
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (var cartItem in Model.items)
        {
            <tr>
                
                <td>
                    <h4>
                      @Html.ActionLink(@cartItem.ItemName, "BookView", "Home", new { bookId = @cartItem.BookID }, null)
                     </h4>
                </td>
                <td>
                    <h4>@cartItem.BookCode</h4>
                </td>
                <td>
                    <h4>@cartItem.Price</h4>
                </td>
                <td>
                    <input type="text" size="2" maxlength="2" value="@cartItem.Quantity" id="@cartItem.BookID" name="@cartItem.BookID" onkeypress="return isNumberKey(event,@cartItem.BookID); " />                    
                    <input type="button" value="Update Quantity" onclick="fnUpdateQuantity(@cartItem.BookID);" />
                    <input type="button" value="Remove" onclick="fnRemoveCartItem(@cartItem.BookID);" />
                    
                </td>                
                <td>
                    <h4>@cartItem.Total</h4>
                </td>
            </tr>
        }
        </tbody>
    </table>
    <div>
    
            <h2 >Total :  <span style="color:Red"> @Model.Total </span></h2>
         
    </div>
}
else { 
 <h1>Your cart has not any items</h1>
}